package com.group3.controller.adminController;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.group3.controller.Validated.Add;
import com.group3.controller.Validated.Update;
import com.group3.domain.Group;
import com.group3.domain.StudentGroupInfo;
import com.group3.domain.StudentInfo;
import com.group3.pojo.receive.GroupReceive;
import com.group3.pojo.receive.Students;
import com.group3.pojo.result.GroupResult;
import com.group3.pojo.Page;
import com.group3.service.AGroupService;
import com.group3.utils.Result;
import com.group3.utils.ResultUtil;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import lombok.Data;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * AGroupController
 *
 * @author HY
 * 2021/06/04 9:06
 **/

//管理小组接口
@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admin/group")
public class AGroupController {

    @Resource
    private AGroupService aGroupService;

    //增加项目组
    @PostMapping(value = "")
    @ApiOperation(value = "增加小组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupName", value = "小组名字", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "statue", value = "小组状态", required = true,
                    dataType = "Integer"),
    })
    public Result addGroup(
            @NotEmpty @RequestParam String groupName, @RequestParam Integer statue) {

        return aGroupService.addGroup(groupName, statue);
    }

    //查看所有小组
    @GetMapping(value = "")
    @ApiOperation(value = "查询所有小组（id，name）")
    @ApiImplicitParam(name = "groupName", value = "小组名字",
            dataType = "String")
    public Result<List<GroupResult>> selectGroup(String groupName) {

        return aGroupService.selectGroup(groupName);
    }

    //    修改小组信息
    @PutMapping(value = "")
    @ApiOperation(value = "修改小组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "小组id", required = true,
                    dataType = "int"),
            @ApiImplicitParam(name = "groupName", value = "小组名字", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "小组状态", value = "小组状态", required = true,
                    dataType = "String"),
    })
    public Result updateGroup(GroupReceive groupReceive) {

        return aGroupService.updateGroup(groupReceive);
    }

    //    删除小组
    @DeleteMapping(value = "")
    @ApiOperation(value = "删除小组信息")
    @ApiImplicitParam(name = "groupId", value = "小组id", required = true,
            dataType = "Integer")
    public Result deleteGroup(Integer groupId) {

        return aGroupService.deleteGroup(groupId);
    }

    //    根据小组id查询小组学生
    @GetMapping(value = "/students")
    @ApiOperation(value = "根据小组id和条件查找小组内学生")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "小组id", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(name = "studentName", value = "学生姓名",
                    dataType = "String"),
            @ApiImplicitParam(name = "studentId", value = "学生学号",
                    dataType = "String"),
            @ApiImplicitParam(name = "pageNumber", value = "分页页码",
                    dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",
                    dataType = "Integer"),
    })
    public Result<List<StudentGroupInfo>> selectStudentByGroup(
            Integer groupId,
            String studentName,
            String studentId,
            Page page) {

        return aGroupService.selectStudentByGroup(groupId,
                studentName, studentId, page);
//        return ResultUtil.success(groupId+studentName+studentId+page.toString());
    }

    //    根据小组id新增小组内学生
    @PostMapping(value = "/student")
    @ApiOperation(value = "根据小组id新增小组内学生")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "groupId", value = "小组id",required = true,
//                    dataType = "int"),
//            @ApiImplicitParam(name = "studentIds", value = "学生学号集合",required = true,
//                    dataType = "List<String>"),
//    })
    @ApiOperationSupport(ignoreParameters = "newGroupId")
    public Result addStudentsToGroup(
            @Validated(Add.class) @RequestBody Students students
    ) {
        return aGroupService.addStudentsToGroup(students);
    }



    //    根据小组id和将小组内学生移到另一个小组
    @PutMapping(value = "/Remove")
    @ApiOperation(value = "根据小组id和将小组内学生移到另一个小组")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "groupId", value = "原小组id",required = true,
//                    dataType = "Integer"),
//            @ApiImplicitParam(name = "newGroupId", value = "更新后小组id",required = true,
//                    dataType = "Integer"),
//            @ApiImplicitParam(name = "studentIds", value = "学生学号集合",required = true,
//                    dataType = "List<String>"),
//    })
    public Result updateStudentsToGroup(
            @Validated(Update.class) @RequestBody Students students) {

//        return ResultUtil.success(students.toString());
        return aGroupService.updateStudentsToGroup(students);
    }

    //    将学生集合从小组中移除
    @DeleteMapping(value = "/students")
    @ApiOperation(value = "将学生集合从小组中移除")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "groupId", value = "小组id",required = true,
//                    dataType = "int"),
//            @ApiImplicitParam(name = "studentIds", value = "学生学号集合",required = true,
//                    dataType = "List<String>"),
//    })
    @ApiOperationSupport(ignoreParameters = "newGroupId")
    public Result deleteStudentsToGroup(
            @Validated(Update.class) @ModelAttribute Students students) {

        return ResultUtil.success(students.toString());
//        return aGroupService.deletStudentsToGroup(students);
    }

    //    将学生设置为组长
    @PutMapping(value = "/studentId")
    @ApiOperation(value = "将学生设置为组长")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "小组id", required = true,
                    dataType = "Integer"),
            @ApiImplicitParam(name = "studentId", value = "学生学号", required = true,
                    dataType = "String"),
    })
    public Result PutGroupOfLeader(
            Integer groupId, String studentId
    ) {

//        return ResultUtil.success(groupId + studentId);
        return aGroupService.PutGroupOfLeader(groupId, studentId);
    }


    //TODO 没写完


}
